package com.leetcode.dynamic_programming;

/**
 * @author Dennis Li
 * @date 2020/7/19 11:16
 */
public class JumpGame_55 {

    // 用贪心更好
    public boolean canJump(int[] nums) {
        int len = nums.length;
        int right = 0;
        for (int i = 0; i < len; i++) {
            if (i <= right) {
                // 注意最大值的计算是当前的坐标加上能够跳到的最大位置
                right = Math.max(right, i + nums[i]);
                if (right >= len - 1) return true;
            }
        }
        return false;
    }

}
